package org.java.user.controller;

import org.java.user.api.damain.User;
import org.java.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("user-info")
public class UserInfoController {
    @Autowired
    private UserService userService;
    @GetMapping
    //如果user-center服务已经配置好资源服务，那么得到的Principal参数就是用户服务
        public User get(@AuthenticationPrincipal OAuth2Authentication principal){
        String id = principal.getName();
        User user =  this.userService.findById(id);
        return user;
    }
}
